package com.kang.controller;

import com.kang.entity.Notify;
import com.kang.service.NotifyService;
import com.kang.util.WebResponse;
import com.kang.vo.ParamInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "公告接口")
@RestController
@RequestMapping("/admin/notify")
@Slf4j

public class NotifyController {

    @Autowired
    private NotifyService notifyService;


    /**
     * 传发布状态 status 1 发布 2待发布
     */
    @ApiOperation("发布公告")
    @PostMapping("insertNotify")
    public WebResponse insertNotify(@RequestBody Notify notify) {
        try {
            return WebResponse.resSuccess("发布公告成功",notifyService.insertNotify(notify));
        } catch (Exception ex) {
            log.error("发布公告失败",ex);
            return WebResponse.resFail("发布公告失败",null);
        }
    }

    @ApiOperation("删除公告")
    @PostMapping("deleteNotify")
    public WebResponse deleteNotify(@RequestBody Notify notify) {
        try {
            return WebResponse.resSuccess("删除公告成功",notifyService.deleteNotify(notify));
        } catch (Exception ex) {
            log.error("删除公告失败",ex);
            return WebResponse.resFail("删除公告失败",null);
        }
    }

    @ApiOperation("未发布转发布")
    @PostMapping("updateStatus")
    public WebResponse updateStatus(@RequestBody Notify notify) {
        try {
            return WebResponse.resSuccess("未发布转发布成功",notifyService.updateStatus(notify));
        } catch (Exception ex) {
            log.error("未发布转发布失败",ex);
            return WebResponse.resFail("未发布转发布失败",null);
        }
    }


    @ApiOperation("条件查询公告")
    @GetMapping("getNotifyPage")
    public WebResponse getNotifyPage(ParamInfo vo) {
        try {
            return WebResponse.resSuccess("条件查询公告成功",notifyService.getNotifyPage(vo));
        } catch (Exception ex) {
            log.error("条件查询公告失败",ex);
            return WebResponse.resFail("条件查询公告失败",null);
        }
    }

    @ApiOperation("修改公告内容")
    @PostMapping("updateNotify")
    public WebResponse updateNotify(@RequestBody Notify notify) {
        try {
            return WebResponse.resSuccess("修改公告成功",notifyService.updateNotify(notify));
        } catch (Exception ex) {
            log.error("修改公告失败",ex);
            return WebResponse.resFail("修改公告失败",null);
        }
    }

    @ApiOperation("查看公告详情")
    @GetMapping("getNotifyById")
    public WebResponse getNotifyById(Integer id) {
        try {
            return WebResponse.resSuccess("查看公告详情成功",notifyService.getNotifyById(id));
        } catch (Exception ex) {
            log.error("查看公告详情失败",ex);
            return WebResponse.resFail("查看公告详情失败",null);
        }
    }

    @ApiOperation("用户端展示")
    @GetMapping("getNotifyShow")
    public WebResponse getNotifyShow() {
        try {
            return WebResponse.resSuccess("用户端展示成功",notifyService.getNotifyShow());
        } catch (Exception ex) {
            log.error("用户端展示失败",ex);
            return WebResponse.resFail("用户端展示失败",null);
        }
    }


}
